﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Singleton
{
    /*双重检测的单例
     * 支持延迟加载、支持高并发
     */
    internal class XmlConfig
    {
        //private readonly XmlConfig _config;
        private static volatile XmlConfig _config;
        static object _lock = new object();
        private XmlConfig()
        {
        }

        public static XmlConfig GetInstance()
        {
            if (_config==null)
            {
                lock (_lock)
                {
                    if (_config==null)
                    {
                        _config = new XmlConfig(); 
                    }
                }
            }
            return _config;
        }

        public void LoadXml()
        {
            Console.WriteLine("Loading xml config...");
        }
    }
}
